package hutool;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.id.NanoId;
import cn.hutool.core.util.StrUtil;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.util.Date;

/**
 * @author DengZhiYuan
 * @version 1.0
 * @date 2022/12/30 11:29
 */
public class StrUtilDemo {

    public static void main(String[] args) throws Exception {
        StrUtilDemo strTest = new StrUtilDemo();
//        strTest.sqlTest();
//        strTest.numFormat();
//        strTest.orderNo();
//        strTest.randomChar();
//        try {
//            strTest.newExcept();
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        strTest.indexStr();
//          strTest.getPath();
//          strTest.cryptStr();
//          strTest.decodeStr();
          strTest.mkdirTest();
    }

    public void sqlTest(){
        String sql1;
        String QueuesTime = "";
        String strHDTable = "HD"+ DateUtil.format(new Date(), DatePattern.SIMPLE_MONTH_PATTERN);
        String strDay = DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
        int rc = 0;
        String caller = "dzy";
        //来电进入排队的时间
        sql1 = StrUtil.indexedFormat("SELECT LEN_TALK AS QUETIME FROM {0} WHERE AUTOID=(SELECT MAX(AUTOID) AS AUTOID FROM {0}" +
                " WHERE SDATE='{1}' AND CALLER='{2}' AND CALLTYPE=10)", strHDTable, strDay, caller);
        System.out.println(sql1);
    }

    public void numFormat(){
        DecimalFormat df1 = new DecimalFormat("000");
        String format = df1.format(1);
        System.out.println(format);

        Integer integer = new Integer("002");
        System.out.println(integer);

    }

    public void orderNo(){
        String orderNumber = "123456789DGY002";
        if(StrUtil.contains(orderNumber, "DGY")){
            orderNumber = StrUtil.sub(orderNumber,0,orderNumber.length()-6);
        }else if(StrUtil.contains(orderNumber, "ZJ")){
            orderNumber = StrUtil.sub(orderNumber,0,orderNumber.length()-5);
        }
        System.out.println(orderNumber);
    }

    public void randomChar(){
        String randomNanoId = NanoId.randomNanoId(16);
        System.out.println(randomNanoId.length());
    }

    public void length(){
        String union = " UNION ALL";
        System.out.println(union.length());
    }

    public void newExcept(){
        throw new RuntimeException("1111");
    }


    public void indexStr(){
        String begin = "https://freeswitch.obs.cn-north-4.myhuaweicloud.com";
        String s = "/home/ToneThink/recordings/recwav/20230112/9a678d41-69df-49c1-9f2f-41cffba2514d.wav";
        int recwav = StrUtil.indexOfIgnoreCase(s, "recwav");
        String subSuf = StrUtil.subSuf(s, recwav+6);
        System.out.println(subSuf);
    }

    public void getPath(){
        String s = "D:\\远盟文档\\禅道整理\\禅道1340北京人寿2.0\\1340上线SQL.txt";
        System.out.println(new File(s).getPath());
    }

    public void cryptStr(){
        String appKey = "7c689e2a-e359-47d6-b1df-65446c6fa376";
        String replace = appKey.replace("-", "");
        System.out.println(replace.length());
    }
    public void decodeStr() throws UnsupportedEncodingException {
        String query = "jsoncallback=&cmd=ATSetLeaveSeat&uid=8003&state=1&cause=%E5%B0%8F%E4%BC%91";
        query = URLDecoder.decode(query, "utf-8");
        System.out.println(query);
    }

    public void mkdirTest() throws Exception {
        File file = new File("D:\\opt\\upload\\temp\\work\\Tomcat\\localhost\\ROOT\\opt\\upload\\hbs\\import\\advanceFinance");
        file.mkdirs();
    }

}
